import api from '../../api/index.js'
import Function from '../../common/function.js'
// import config from '../../common/config.js'
const home = {
	state: {
		eleInfo: {}, //电梯信息
		recordList:[], //记录分页
		maintainRecordList:{}, //保养记录
		repairsRecordList: {}, //维保记录
		tabs: 0, //记录的下标
	},
	mutations: {
		//电梯详情
		set_EleInfo(state, opt) {
			state.eleInfo = opt;
			Function.LinkTo('/pages/home/ele-details')
		},
		set_tabs(state, opt){
			state.tabs = opt;
			state.recordList = []
		},
		//保养记录
		set_maintainRecord(state, opt) {
			state.maintainRecordList = opt;
			this.commit('set_recordList', opt)
		},
		//维保记录
		set_repairsRecord(state, opt) {
			state.repairsRecordList = opt;
			this.commit('set_recordList', opt)
		},
		//记录分页
		set_recordList(state, opt) {
			if(state.tabs == 1) {
				state.recordList = state.recordList.concat(opt.records)
			}else{
				state.recordList = state.recordList.concat(opt.records)
			}
		}
	},
	actions: {
		// 获取电梯详情
		scan_Code({commit, state}, opt) {
			api.scanCode_getEleInfo(opt)
			.then(res => {
				// console.log('res ==>', res)
				if(res.data.code == 200) {
					commit('set_EleInfo', res.data.data);
				}
			})
		},
		//更换手机号
		change_Pone(state, opt) {
			return api.modifyPhone(opt)
		},
		// 保养记录
		get_maintainRecord({commit, state}, opt) {
			api.maintain_getCompletePage(opt)
			.then(res => {
				if(res.data.code == 200) {
					commit('set_maintainRecord', res.data.data)
				}
			})
			
		},
		// 维保记录
		get_repairsRecord({commit, state}, opt) {
			api.repairs_getCompletePage(opt)
			.then(res => {
				if(res.data.code == 200) {
					commit('set_repairsRecord', res.data.data)
				}
			})
			
		}
		
	}
}

export default home